import pytest

from api.order_api.setmeal_order_api.Setmeal_order_api import SetmealOrderApi
from utils.utils import _assert


class TestsetmealOrder:

    @pytest.mark.run(order=1)
    def test01_order_create(self):
        """
        新增套餐订单接口
        :return:
        """
        # 商店编号
        storeId = SetmealOrderApi().store().json()['data']["records"][0].get('storeId')
        # 用户编号
        userId = SetmealOrderApi().userID(storeId).json()['data']["records"][0].get('id')
        # 套餐价格
        Price1 = int(SetmealOrderApi().order_setmeal(
            storeId, userId).json()['data']['records'][0]['salePrice'])
        # 套餐1
        goodsId1 = SetmealOrderApi().order_setmeal(
            storeId, userId).json()['data']['records'][0]['suitRuleList'][0]['suitRuleItemList'][0]['itemId']
        # 套餐2
        goodsId2 = SetmealOrderApi().order_setmeal(
            storeId, userId).json()['data']['records'][0]['suitRuleList'][0]['suitRuleItemList'][1]['itemId']
        # 套餐ID
        suitId = SetmealOrderApi().order_setmeal(
            storeId, userId).json()['data']['records'][0]['id']
        # 规则标识
        ruleId1 = SetmealOrderApi().order_setmeal(
            storeId, userId).json()['data']['records'][0]['suitRuleList'][0]['suitRuleItemList'][0]['ruleId']
        ruleId2 = SetmealOrderApi().order_setmeal(
            storeId, userId).json()['data']['records'][0]['suitRuleList'][0]['suitRuleItemList'][0]['ruleId']
        # 声明全局变量
        global orderCode, id, response_
        # 发送接口请求
        response_ = SetmealOrderApi().order_create(storeId=storeId, userId=userId, Price=Price1,
                                                   goodsId=goodsId1, goodsId2=goodsId2, suitId=suitId, ruleId1=ruleId1,
                                                   ruleId2=ruleId2)
        orderCode = response_.json()['data']['orderCode']
        id = response_.json()['data']['id']

        _assert(response_, 200, 0, True)


    @pytest.mark.run(order=2)
    def test02_all_order_search(self):
        """
        查询服务订单接口
        :return:
        """
        response = SetmealOrderApi().all_order_search(orderCode=orderCode)
        _assert(response, 200, 0, True)


    @pytest.mark.run(order=3)
    def test03_order_editor(self):
        """
        编辑服务订单
        :return:
        """
        response = SetmealOrderApi().order_editor(id)
        global data
        data = response.json()["data"]
        _assert(response, 200, 0, True)


    @pytest.mark.run(order=4)
    def test04_order_update(self):
        """
        确认编辑服务订单接口
        :return:  orderId,storeId,userId,Goodsid,price
        """
        orderId = response_.json()['data']['id']
        response = SetmealOrderApi().order_update(orderId=orderId)
        _assert(response, 200, 0, True)


    @pytest.mark.run(order=5)
    def test05_order_details(self):
        """
        服务订单详情接口
        :return:
        """
        response = SetmealOrderApi().order_details(id)
        _assert(response, 200, 0, True)


    @pytest.mark.run(order=6)
    def test06_order_pass(self):
        """
        服务订单通过审核接口
        :return:
        """
        response = SetmealOrderApi().order_pass(id)
        _assert(response, 200, 0, True)


    @pytest.mark.run(order=7)
    def test07_order_applyRefund(self):
        """
        提出申请退款服务订单
        :return:
        """
        response = SetmealOrderApi().order_applyRefund("好好学习，天天向上", id)
        _assert(response, 200, 0, True)


    @pytest.mark.run(order=8)
    def test08_order_agree(self):
        """
        服务订单申请退款同意
        :return:
        """
        response = SetmealOrderApi().order_agree(id)
        print(id)
        _assert(response, 200, 0, True)


    @pytest.mark.run(order=9)
    def test04_order_orderDelete(self):
        """
        删除服务订单
        :return:
        """
        ""
        response = SetmealOrderApi().order_orderDelete(orderId=id)
        _assert(response, 200, 0, True)
